import http from '@/http'

export const userListApi = (params: IUserParams): RES<IUserList> => http.get("/admin/list", { params })


export const userStatusApi = (id: number, status: number): RES<number> => http.post(`admin/updateStatus/${id}?status=${status}`)

// 用户注册
export const userRegisterApi = (params: IList): RES<IList> => http.post(`/admin/register`, params)
// 获取当前用户信息
export const getUserByIdApi = (id: number): RES<IList> => http.get(`/admin/${id}`)

// 修改用户信息
export const updateUserApi = (params: IList): RES<number> => http.post(`/admin/update/${params.id}`, params)

// 获取所有角色
export const userListAllApi = (): RES<IListAll[]> => http.get('/role/listAll')

// 获取角色相关菜单
export const getUserMenuApi = (roleId: number): RES<IListAll[]> => http.get(`/admin/role/${roleId}`)

export const setUserUpdateApi = (adminId: number, roleIds: number[]): RES<number> => http.post(`/admin/role/update?adminId=${adminId}&roleIds=${roleIds.join(',')}`)

// 根据角色名称分页获取角色列表
export const getRoleListApi = (params: IUserParams): RES<IRoleList> => http.get(`/role/list`, { params })

// 修改角色状态
export const setReoStateApi = (id: number, status: number): RES<number> => http.post(`/role/updateStatus/${id}?status=${status}`)

//添加角色
export const addRoleApi = (params: { name: string; description: string; status: number }): RES<number> => http.post(`/role/create`, params)

//修改角色
export const editRoleApi = (params: {
  id?: number;
  name: string;
  description: string;
  status: number;
}) => http.post(`/role/update/${params.id}`, params)

//获取角色相关菜单
export const getResourceIdApi = (roleId: number): RES<IRoleList[]> => http.get(`/role/listResource/${roleId}`)

// 查询所有后台资源分类
export const resourceCategoryAllApi = (): RES<IRoleCategory[]> => http.get('/resourceCategory/listAll')

// 查询所有后台资源
export const resourceListAllApi = (): RES<IRoleList[]> => http.get('/resource/listAll')

// 给角色分配资源    
export const allocResourceApi = (params:IAllocResourceParams):RES<number> => http.post(`/role/allocResource?resourceIds=${params.resourceIds.join(',')}&roleId=${params.roleId}`)

// 树形结构返回所有菜单列表
export const treeListApi = ():RES<ITreeList[]>=>http.get('/menu/treeList')
